{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "846061b9-4829-48a0-a2be-dae592b8f95a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0901b4de-dd28-4433-ac7b-8db0d9a0f995",
   "metadata": {},
   "source": [
    "### Size of Numpy array in bytes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2cec0596-d393-479b-bf67-3deddec0ea9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter integers seperated by space. Press ENTER to end... 34 23 67 89\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Given sequence is\n",
      "[34, 23, 67, 89]\n",
      "Number of elements in the numpy array: 4\n",
      "Total bytes consumed by the numpy array: 16\n",
      "Size in bytes of each element in the numpy array: 4\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # feed integer array from user\n",
    "    arr = list(map(int, input(\"Enter integers seperated by space. Press ENTER to end...\").split()))\n",
    "    print(\"Given sequence is\")\n",
    "    print(arr)\n",
    "    # convert Python array to Numpy array\n",
    "    np_array = np.array(arr, dtype=int)\n",
    "    print(f\"Number of elements in the numpy array: {np_array.size}\")\n",
    "    print(f\"Total bytes consumed by the numpy array: {np_array.nbytes}\")\n",
    "    print(f\"Size in bytes of each element in the numpy array: {(np_array.nbytes)//(np_array.size)}\")\n",
    "except ValueError as e:\n",
    "    print(\"ERROR: Please enter only integers !!!\")\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e18b28b-796a-428f-96f7-cd530fd0cfd1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
